package net.georel.representation.categorisation.datasource;

import java.util.HashSet;
import java.util.Set;

import org.geotools.factory.CommonFactoryFinder;
import org.geotools.feature.FeatureCollection;
import org.geotools.feature.FeatureIterator;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.filter.Filter;
import org.opengis.filter.FilterFactory2;
import org.opengis.filter.identity.FeatureId;

public class WebFeatureInfo {

	private FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null);
	
	public String getFeatureInfo(String featureID, FeatureCollection fc){
		
		
		FeatureId fid = ff.featureId( featureID );
		Set<FeatureId> fids = new HashSet<FeatureId>();
	    fids.add( fid );
	    Filter filter = ff.id( fids );
	    FeatureCollection SelectedFeature = fc.subCollection(filter);
	    int value = SelectedFeature.size();
	    FeatureIterator featIT = SelectedFeature.features();
	    String barName = "null";
	    while (featIT.hasNext()){
	    	SimpleFeature feature = (SimpleFeature) featIT.next();
	    	barName = (String) feature.getAttribute("cont");
	    }
	    
		return barName;
	}
}
